home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gsl.idb / usr / freeware / include / gsl_math.h.z / gsl_math.h
Encoding:
C/C++ Source or Header  |  1999-07-16  |  3.5 KB  |  160 lines

  1. #ifndef _GSL_MATH_H
  2. #define _GSL_MATH_H
  3. #include <math.h>
  4.  
  5. #ifndef M_E
  6. #define M_E        2.71828182845904523536028747135    /* e */
  7. #endif
  8.  
  9. #ifndef M_SQRT2
  10. #define M_SQRT2       1.41421356237309504880168872421
  11. #endif
  12.  
  13. #ifndef M_SQRT3
  14. #define M_SQRT3       1.73205080756887729352744634151
  15. #endif
  16.  
  17. #ifndef M_PI
  18. #define M_PI       3.14159265358979323846264338328
  19. #endif
  20.  
  21. #ifndef M_PI_4
  22. #define M_PI_4     0.78539816339744830966156608458    /* pi/4 */
  23. #endif
  24.  
  25. #ifndef M_SQRTPI
  26. #define M_SQRTPI   1.77245385090551602729816748334    /* sqrt(pi) */
  27. #endif
  28.  
  29. #ifndef M_LN10
  30. #define M_LN10     2.30258509299404568401799145468    /* ln(10) */
  31. #endif
  32.  
  33. #ifndef M_LN2
  34. #define M_LN2        0.69314718055994530941723212146    /* ln(2) */
  35. #endif
  36.  
  37. #ifndef M_LNPI
  38. #define M_LNPI     1.14472988584940017414342735135    /* ln(pi) */
  39. #endif
  40.  
  41. #ifndef M_EULER
  42. #define M_EULER    0.57721566490153286060651209008    /* Euler constant */
  43. #endif
  44.  
  45.  
  46. /* magic constants; mostly for the benefit of the implementation */
  47. #include <gsl_machine.h>
  48. #include <gsl_precision.h>
  49.  
  50.  
  51. /* other needlessly compulsive abstractions */
  52.  
  53. #define GSL_IS_ODD(n)  ((n) & 1)
  54. #define GSL_IS_EVEN(n) (!(GSL_IS_ODD(n)))
  55. #define GSL_SIGN(x)    ((x) >= 0.0 ? 1 : -1)
  56.  
  57. /* Return nonzero if x is a real number, i.e. non NaN or infinite. */
  58. /* FIXME: Is this correct way to check if something is real? */
  59. #define GSL_IS_REAL(x) (0 * (x) == 0)
  60.  
  61. /* Define MAX and MIN macros/functions if they don't exist. */
  62.  
  63. /* plain old macros for general use */
  64. #define GSL_MAX(a,b) ((a) > (b) ? (a) : (b))
  65. #define GSL_MIN(a,b) ((a) < (b) ? (a) : (b))
  66.  
  67. /* inline-friendly strongly typed versions */
  68. #ifdef HAVE_INLINE
  69.  
  70. inline int GSL_MAX_INT (int a, int b);
  71. inline int GSL_MIN_INT (int a, int b);
  72. inline double GSL_MAX_DBL (double a, double b);
  73. inline double GSL_MIN_DBL (double a, double b);
  74. inline long double GSL_MAX_LDBL (long double a, long double b);
  75. inline long double GSL_MIN_LDBL (long double a, long double b);
  76.  
  77. inline int
  78. GSL_MAX_INT (int a, int b)
  79. {
  80.   return GSL_MAX (a, b);
  81. }
  82.  
  83. inline int
  84. GSL_MIN_INT (int a, int b)
  85. {
  86.   return GSL_MIN (a, b);
  87. }
  88.  
  89. inline double
  90. GSL_MAX_DBL (double a, double b)
  91. {
  92.   return GSL_MAX (a, b);
  93. }
  94.  
  95. inline double
  96. GSL_MIN_DBL (double a, double b)
  97. {
  98.   return GSL_MIN (a, b);
  99. }
  100.  
  101. inline long double
  102. GSL_MAX_LDBL (long double a, long double b)
  103. {
  104.   return GSL_MAX (a, b);
  105. }
  106.  
  107. inline long double
  108. GSL_MIN_LDBL (long double a, long double b)
  109. {
  110.   return GSL_MIN (a, b);
  111. }
  112. #else
  113. #define GSL_MAX_INT(a,b)   GSL_MAX(a,b)
  114. #define GSL_MIN_INT(a,b)   GSL_MIN(a,b)
  115. #define GSL_MAX_DBL(a,b)   GSL_MAX(a,b)
  116. #define GSL_MIN_DBL(a,b)   GSL_MIN(a,b)
  117. #define GSL_MAX_LDBL(a,b)  GSL_MAX(a,b)
  118. #define GSL_MIN_LDBL(a,b)  GSL_MIN(a,b)
  119. #endif /* HAVE_INLINE */
  120.  
  121. /* Definition of an arbitrary function with parameters */
  122.  
  123. struct gsl_function_struct 
  124. {
  125.   double (* function) (double x, void * params);
  126.   void * params;
  127. };
  128.  
  129. typedef struct gsl_function_struct gsl_function ;
  130.  
  131. #define GSL_FN_EVAL(F,x) (*((F)->function))(x,(F)->params)
  132.  
  133. /* Definition of an arbitrary function returning two values, r1, r2 */
  134.  
  135. struct gsl_fdf_struct 
  136. {
  137.   double (* f) (double x, void * params);
  138.   double (* df) (double x, void * params);
  139.   void (* fdf) (double x, void * params, double * f, double * df);
  140.   void * params;
  141. };
  142.  
  143. typedef struct gsl_fdf_struct gsl_fdf ;
  144.  
  145. #define GSL_FDF_F_EVAL(FDF,x) (*((FDF)->f))(x,(FDF)->params)
  146. #define GSL_FDF_DF_EVAL(FDF,x) (*((FDF)->df))(x,(FDF)->params)
  147. #define GSL_FDF_EVAL(FDF,x,y,dy) (*((FDF)->fdf))(x,(FDF)->params,(y),(dy))
  148.  
  149. /* Definition of an interval */
  150.  
  151. struct gsl_interval_struct 
  152. {
  153.   double lower;
  154.   double upper;
  155. };
  156.  
  157. typedef struct gsl_interval_struct gsl_interval;
  158.  
  159. #endif /* !_GSL_MATH_H */
  160.